package com.example.mybatis;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import oj.common.core.contants.JwtConstants;
import oj.common.core.utils.ThreadLocalUtil;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("11111111111111111userId:{}"+ThreadLocalUtil.get(JwtConstants.LOGIN_USER_ID,Long.class));
        this.strictInsertFill(metaObject,"createBy", Long.class, ThreadLocalUtil.get(JwtConstants.LOGIN_USER_ID,Long.class));
        this.strictInsertFill(metaObject,"createTime", LocalDateTime.class, LocalDateTime.now() );

        this.strictInsertFill(metaObject,"updateBy", Long.class, ThreadLocalUtil.get(JwtConstants.LOGIN_USER_ID,Long.class) );
        this.strictInsertFill(metaObject,"updateTime", LocalDateTime.class, LocalDateTime.now() );
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject,"updateTime", LocalDateTime.class, LocalDateTime.now() );
        this.strictInsertFill(metaObject,"updateBy", Long.class, 100L );
    }

}
